package com.nimitz.web.controller.pollution;

import com.nimitz.common.core.controller.BaseController;
import com.nimitz.common.core.domain.AjaxResult;
import com.nimitz.common.core.page.TableDataInfo;
import com.nimitz.pollution.domain.Pollution;
import com.nimitz.pollution.service.PollutionService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/smart/pollution")
public class PollutionController extends BaseController {


    @Autowired
    private PollutionService pollutionService;

    // 查看公告
    @GetMapping("/list")
    public TableDataInfo listPollution(Pollution pollution) {
        startPage();
        List<Pollution> pollutions = pollutionService.getPollutionsForPagination(pollution);
        return getDataTable(pollutions);
    }
    @PostMapping("/add")
    public AjaxResult addPollution(@RequestBody Pollution pollution) {
        pollutionService.addPollution(pollution);
        return AjaxResult.success("操作成功");
    }


    //通过Id获取
    @GetMapping("/get")
    public AjaxResult getPollutionById(@RequestParam Long id) {
        Pollution pollution = pollutionService.selectPollutionById(id);
        return AjaxResult.success(pollution);
    }

    // 修改公告
    @PutMapping("/update")
    public AjaxResult updatePollution(@RequestBody Pollution pollution) {
        pollutionService.updatePollution(pollution);
        return AjaxResult.success("修改成功");
    }

    // 删除公告
    @DeleteMapping("/delete")
    public AjaxResult deletePollution(@RequestParam Long id) {
        pollutionService.deletePollution(id);
        return AjaxResult.success("删除成功");
    }

}
